import express from 'express';
import data from '../data';
import ResMsg from '../common/ResMsg';
const userRouter = express.Router();


userRouter.post('/login', (req, res, next) => {
    req.on('data', r => {
        let params = JSON.parse(decodeURIComponent(r));
        let resMsg = new ResMsg(false);
        resMsg.msg = '用户不存在';
        for (const item of data.users) {
            if (params.id === item.id && params.pwd === item.pwd) {
                resMsg = new ResMsg(false);
                resMsg.msg = '登录成功';
                resMsg.userInfo = item;
            } else if (params.id === item.id && params.pwd !== item.pwd) {
                resMsg.msg = '密码不正确';
            }
        }
        res.json(resMsg);
    });
});

export default userRouter;